/**
 * Created by NamLaptop on 7/13/2014.
 */

var MyTileNoEvent = MySprite.extend({
    ctor: function(src){
        this._super();
        this.src = src;
        this.initWithFile(src);
        this.pos = {x: 0, y: 0};
        this.ID = null;
        this.isDefaultOver = false;
    }
});

var MyTile = MyTileNoEvent.extend({

    ctor: function(src){
        this._super(src);
        this.textSprite = null;
        this.isShowText = false;
        this.textWin = "";
        this.textSprite = cc.LabelTTF.create("test", INFO.MESSAGEBOX.FONT, 12);
        this.addChild(this.textSprite, 1500);
        this.textSprite.setPosition(cc.p(INFO.TILE.BOT_WIDTH/2 - 2, INFO.TILE.BOT_HEIGHT - 15));
        this.textSprite.setColor(cc.BLUE);
        this.textSprite.setVisible(false);

    },

    showText: function(text){
        if(this._parent != null){
            if(!this.isShowText){
                this.isShowText = true;
                if(this.textWin.length > 0){
                    if(this.textWin.indexOf(text) < 0) {
                        this.textWin = text + ", " + this.textWin;
                    }
                }
                else{
                    this.textWin = text;
                }
                this.textSprite.setString(this.textWin);
                this.textSprite.setVisible(true);
            }
        }
    },

    hideText: function(){
        if(this.isShowText){
            this.textWin = "";
            this.isShowText = false;
            this.textSprite.setVisible(false);
        }
    },

    defaultMouseOver: function(){
        this.isDefaultOver = true;
        var move = cc.MoveBy.create(0.1, cc.p(0,7));
        this.runAction(cc.Sequence.create(move));
       // if(this.textSprite != null){
       //     var move2 = cc.MoveBy.create(0.1, cc.p(0,7));
       //     this.textSprite.runAction(cc.Sequence.create(move2));
       // }
    },

    defaultMouseOut: function(){
        this.isDefaultOver = false;
        var move = cc.MoveBy.create(0.1, cc.p(0,-7));
        this.runAction(cc.Sequence.create(move));
        //if(this.textSprite != null){
        //   var move2 = cc.MoveBy.create(0.1, cc.p(0,-7));
        //    this.textSprite.runAction(cc.Sequence.create(move2));
        //}
    },

    // Override
    onMouseOver: function(){
        this.defaultMouseOver();
    },

    onMouseOut: function(){
        this.defaultMouseOut();
    },

    //Override
    _onTap: function(touch, event){
        this.onTap(touch, event);
    }
});

